package com.j1ay.forum.controller;

import com.j1ay.forum.model.pojo.po.Role;
import com.j1ay.forum.model.pojo.vo.Result;
import com.j1ay.forum.service.RoleService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

/**
 * @Author J1ay
 * @Date 2021/12/20 22:16
 * @Description
 */
@RestController
@RequestMapping("api/role")
public class RoleController {

    @Autowired
    private RoleService roleService;

    @ApiOperation("查询角色列表")
    @GetMapping("list")
    @PreAuthorize("hasAnyAuthority('is:admin')")
    public Result getRoleList() {
        return roleService.getRoleList();
    }

    @ApiOperation("增加角色")
    @PostMapping("add")
    @PreAuthorize("hasAnyAuthority('is:admin')")
    public Result add(@RequestBody Role role) {
        return roleService.add(role);
    }

    @ApiOperation("修改角色")
    @PutMapping("update")
    @PreAuthorize("hasAnyAuthority('is:admin')")
    public Result update(@RequestBody Role role) {
        return roleService.update(role);
    }

    @ApiOperation("删除角色")
    @DeleteMapping("delete/{id}")
    @PreAuthorize("hasAnyAuthority('is:admin')")
    public Result delete(@PathVariable("id") Long id) {
        return roleService.delete(id);
    }
}
